//
//  MNDUserCenterTopSectionCell.m
//  miniwangdai2
//
//  Created by Steven.Yung on 2017/3/28.
//  Copyright © 2017年 谭谭伟. All rights reserved.
//

#import "MNDUserCenterTopSectionCell.h"
#import "MNDUserCenterCollectionCell.h"
#import "MNDUserCenterTopSectionModel.h"

@interface MNDUserCenterTopSectionCell () <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property (strong, nonatomic) UICollectionView *collectionView;

@end


@implementation MNDUserCenterTopSectionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self initialCollectionView];
    }
    
    return self;
}

- (void)initialCollectionView {
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.scrollEnabled = NO;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
    [self.collectionView registerClass:[MNDUserCenterCollectionCell class] forCellWithReuseIdentifier:@"cell"];
    
    [self.contentView addSubview:self.collectionView];
    
    UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).with.insets(insets);
    }];
}

#pragma mark - UICollectionView Datasource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.topSectionArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    MNDUserCenterCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    MNDUserCenterTopSectionModel *model = self.topSectionArr[indexPath.item];
    
    [cell configCellTitle:model.cellTitle subTitle:model.cellSubtitle iconImage:model.cellIcon];
    
    return cell;
}

#pragma mark - UICollectionViewDelegateFlowLayout

- (CGSize )collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CGRect bounds = self.contentView.bounds;
    return CGSizeMake(bounds.size.width / 2, bounds.size.height / 3);
}

#pragma mark - getter

- (NSArray *)topSectionArr {
    
    if (!_topSectionArr) {
        _topSectionArr = [NSArray array];
    }
    
    return _topSectionArr;
}

@end
